import bean.GlobalActionData;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GlobalAction extends ActionSupport {
    private boolean state = true;
    private GlobalActionData data;

    public GlobalActionData getData() {
        return data;
    }

    public void setData(GlobalActionData data) {
        this.data = data;
    }

    @Override
    public void validate() {
        String field3 = data.getField3();
        if (data.getField1() <= 0) {
            addFieldError("data.field1", "字段1的值必须大于0");
            state = false;
        } else if (data.isField2()) {
            addFieldError("data.field2", "字段2的值必须为false");
            state = false;
        } else if (field3 == null || field3.equals("")) {
            addFieldError("data.field3", "字段3的值不能是空字符串");
            state = false;
        }
    }

    public String test() throws Exception {
        String value = state ? SUCCESS : INPUT;
        state = true;
        return value;
    }
}
